
package util.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.e885.log.E885Logger;
import com.e885.util.web.Report;

/**
 * url: 1. from jsp(web/util/*.jsp) 2. htpp://127.0.0.1:8080/TestE885Util/web/util/requestReport?name=grayd.kao<br>
 * 
 * PS:參數 name 在這裏毫無意義, 只是要看 QueryString 是否組合正確
 * 
 * @author Grady.Kao
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2000-2008
 */

public class RequestReportServlet extends HttpServlet
{
	private static final long serialVersionUID = -1675963681165008253L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		StringBuffer buffer = new StringBuffer();

		Report report = new Report();
		report.requestReport( buffer, request );

		System.out.println( buffer.toString() );

		// 以下是測試 JSESSIONID
		E885Logger.testLog.debug( "Is SessionId valid?" + request.isRequestedSessionIdValid() );
		E885Logger.testLog.debug( "request.getSession():" + request.getSession( false ) );
		
		//如果關閉這一行, 那麼 session 都還沒有建立		
		E885Logger.testLog.debug( "session id:" + request.getSession( true ).getId() );

		Cookie[] cookies = request.getCookies();
		if( cookies == null )
			cookies = new Cookie[ 0 ];

		for( int i = 0; i < cookies.length; i++ )
			E885Logger.testLog.debug( "name:" + cookies[ i ].getName() + ", value:" + cookies[ i ].getValue() );
	}
}
